import { VNode, VNodeChild } from 'vue'
import { RouteRecordRaw } from 'vue-router'

/**
 * 菜单相关
 */
export interface IAuthMenu {
    id: number
    pid?: number
    title: string
    path: string
    component: string
    icon?: string
    hidden: 0 | 1
    sort: number
    active: string
    ignore_cache: 0 | 1

    _protect: 0 | 1
}

export type IAuthMenuEditParameter = Omit<
    IAuthMenu,
    'id' | '_protect' | 'sort'
> & {
    id?: IAuthMenu['id']
    sort?: IAuthMenu['sort']
}
export type IAuthMenuDeleteParameter = { id: IAuthMenu['id'] }

export type IAuthMenuRoute = RouteRecordRaw & {
    name: string
    children: []
    meta: {
        pid: IAuthMenu['pid']
        title: IAuthMenu['title'] // 一级菜单名（语言包键名）
        icon?: string // 菜单配置icon
        hidden?: IAuthMenu['hidden'] // 是否在左侧菜单中隐藏该项
        active?: IAuthMenu['active'] // 高亮设置的菜单项
        sort?: IAuthMenu['sort'] // 排序路由菜单项。如果设置该值，值越高，越靠后
        ignore_cache?: IAuthMenu['ignore_cache'] // 如果设置为true页面将不会被缓存
    }
}

export type IAuthMenuTreeNode = {
    id: IAuthMenu['id']
    pid: IAuthMenu['pid']
    nodeTitle: IAuthMenu['title']

    disabled?: boolean // 是否禁用菜单项
    extra?: string | (() => VNodeChild) // 菜单项的额外部分
    icon?: () => VNode // 菜单项的图标
    key: string //菜单项的标识符
    label: string | (() => VNodeChild) //菜单项的内容
    show?: boolean //是否显示菜单项	2.32.2
    children?: IAuthMenuTreeNode[]
}

export type IAuthMenuEditTreeNode = IAuthMenu & {
    children?: IAuthMenuEditTreeNode[]
    disabled: boolean
}

export interface IAuthMenuPinia {
    inited: boolean
    source: IAuthMenu[]
    routes: RouteRecordRaw[]
    editTree: IAuthMenuEditTreeNode[]
    menuTree: IAuthMenuTreeNode[]
    firstRoute?: IAuthMenuRoute
    canExpandKeys: IAuthMenu['id'][]
}

export type IAuthMenuSortParameter = {
    list: {
        id: IAuthMenu['id']
        pid: IAuthMenu['pid']
        sort: IAuthMenu['sort']
    }[]
}
